import cn.puge.usercenter.entity.PugeNewinfo;
import cn.puge.usercenter.service.PugeNewinfoService;
import com.alibaba.excel.EasyExcel;
import org.junit.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LIJW
 * @date 2020/12/3 17:26
 */
public class asdas {

    @Autowired
    private PugeNewinfoService pugeNewinfoService;

    //循环设置要添加的数据，最终封装到list集合中
    private List<PugeNewinfo> data() {


        List<PugeNewinfo> list1 = pugeNewinfoService.list(null);
        List<PugeNewinfo> list = new ArrayList<PugeNewinfo>();

        for (PugeNewinfo pugeNewinfo : list1) {
            PugeNewinfo pugeNewinfo1 = new PugeNewinfo();
            BeanUtils.copyProperties(pugeNewinfo1,pugeNewinfo);
            list.add(pugeNewinfo1);
        }
        return list;
    }


    @Test
    public void da(){
        String fileName = "G:\\11.xlsx";
        // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(fileName, PugeNewinfo.class).sheet("写入方法一").doWrite(data());
    }

}
